//
//  UITableViewCell+HDRepairListCell.m
//  app
//
//  Created by D on 15/8/31.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDRepairListCell.h"

static const CGFloat kMargin = 12.0f;
static const CGFloat kNameW = 80.0f;
static const CGFloat kNameH = 30.0f;
static const CGFloat kStatusW = 60.0f;
static const CGFloat kStatusH = 30.0f;

@implementation HDRepairListCell

-(void)cellWithModel:(HDRepairListModle *)model Row:(NSInteger)row
{
    
    self.frame = CGRectMake(0, 0, UBO_SCREEN.width, 44);
    
    CGFloat kContentW = UBO_WINDOW.width - 2*kMargin - kNameW;
    
    UILabel * nameLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin fy:UB_1_2 oy:-kNameH/2], [self.ubo ow:kNameW oh:kNameH])];
    [nameLab setFont:[UIFont systemFontOfSize:14]];
    [nameLab setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
    [self addSubview:nameLab];
    
    
    UILabel * contentLab = [[UILabel alloc]initWithFrame:CGRectOf([nameLab.ufo fx:1 fy:0], [self.ubo ow:kContentW oh:kNameH])];
    [contentLab setFont:[UIFont systemFontOfSize:14]];
    [contentLab setTextColor:[XCommon hexStringToColor:kColor_black_text]];
    [self addSubview:contentLab];

    
    if (row == 0) {
        kContentW = UBO_WINDOW.width - 2*kMargin - kNameW - kStatusW;
        nameLab.text = @"报修项目：";
        
        contentLab.frame = CGRectOf([nameLab.ufo fx:1 fy:0], [self.ubo ow:kContentW oh:kNameH]);
        contentLab.text = model.repair_item;
        
        UIButton * status = [[UIButton alloc]initWithFrame:CGRectOf([self.ubo fx:1 ox:-kMargin/2-kStatusW fy:UB_1_2 oy:-kStatusH/2], [self.ubo ow:kStatusW oh:kStatusH])];
        [status.titleLabel setFont:[UIFont systemFontOfSize:14]];
//        status.backgroundColor = [UIColor blueColor];
        
        if ([model.status isEqualToString:@"待处理"]){
            [status setTitle:model.status forState:UIControlStateNormal];
            [status setTitleColor:[UIColor colorWithRed:136.0/255.0 green:198.0/255.0 blue:165.0/255.0 alpha:1.0] forState:UIControlStateNormal];
            status.layer.borderColor = [UIColor colorWithRed:136.0/255.0 green:198.0/255.0 blue:165.0/255.0 alpha:1.0].CGColor;
            status.layer.borderWidth = 0.3;
        }else {
                [status setTitle:model.status forState:UIControlStateNormal];
                [status setTitleColor:[UIColor colorWithRed:212.0/255.0 green:157.0/255.0 blue:167.0/255.0 alpha:1.0] forState:UIControlStateNormal];
                status.layer.borderColor = [UIColor colorWithRed:212.0/255.0 green:157.0/255.0 blue:167.0/255.0 alpha:1.0].CGColor;
                status.layer.borderWidth = 0.3;
            }
        [self addSubview:status];
        
    }
    else if (row == 1){
        
        nameLab.text = @"报修时间：";
        contentLab.text = model.creatTime;
        
        UIButton * jiamubiao = [[UIButton alloc]initWithFrame:CGRectOf([self.ubo fx:1 ox:-kMargin/2-kStatusW fy:UB_1_2 oy:-kStatusH/2], [self.ubo ow:kStatusW oh:kStatusH])];
//        jiamubiao.backgroundColor = [UIColor blueColor];
        [jiamubiao setTitle:@"-价目表-" forState:UIControlStateNormal];
        [jiamubiao setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [jiamubiao.titleLabel setFont:[UIFont systemFontOfSize:12]];
        
        jiamubiao.tag = model.com_id.integerValue;
        [jiamubiao addTarget:self action:@selector(jimubiao:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:jiamubiao];
        
        
        
    }
    else if (row == 2){
    
        nameLab.text = @"联 系 人 ：";
        contentLab.text = model.apply_name;
        
    }
    else if (row == 3){
    
        nameLab.text = @"维修地址：";
        contentLab.text = model.address;
        
    }
    
    
}


-(void)jimubiao:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showJiamubiao:)]) {
        [self.delegate showJiamubiao:sender];
    }

}

@end
